home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / sprites / global.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-16  |  11.1 KB  |  383 lines

  1. /*
  2.     global.h
  3.  
  4.     Main application header file
  5.  
  6. */
  7.  
  8. #include <windows.h>
  9. #include <mmsystem.h>
  10. #include <shellapi.h>
  11. #include <commdlg.h>
  12. #include <stdlib.h>
  13. #include <memory.h>
  14. #include "dialogs.h"
  15.  
  16. //
  17. // Menu ids
  18. //
  19.  
  20. #define IDM_LOADBKGND       0x0100
  21. #define IDM_LOADSPRITE      0x0101
  22. #define IDM_PRINT           0x0103
  23. #define IDM_PRINTSETUP      0x0104
  24. #define IDM_EXIT            0x0105
  25. #define IDM_LOADSCENE       0x0106
  26.  
  27. #define IDM_DEBUG0          0x0800
  28. #define IDM_DEBUG1          (IDM_DEBUG0+1)
  29. #define IDM_DEBUG2          (IDM_DEBUG0+2)
  30. #define IDM_DEBUG3          (IDM_DEBUG0+3)
  31. #define IDM_DEBUG4          (IDM_DEBUG0+4)
  32. #define IDM_REFRESH         0x0810
  33. #define IDM_FILLBKGND       0x0811
  34. #define IDM_REDRAW          0x0812
  35. #define IDM_SHOWUPDATES     0x0813
  36. #define IDM_AUTOUPDATE      0x0814
  37.  
  38. #define IDM_HELPCONTENTS    0x0900
  39. #define IDM_ABOUT           0x0901
  40.  
  41. //
  42. // strings
  43. //
  44.  
  45. #define SZ_SPRITE   "Sprite"    // clipboard format name
  46.  
  47. //
  48. // Child window ids
  49. //
  50.  
  51. //
  52. // Raster ops used in drawing
  53. //
  54.  
  55. #define DSa     0x008800C6L
  56. #define DSx     0x00660046L
  57. #define DSo     0x00EE0086L
  58. #define DSna    0x00220326L
  59.  
  60. //
  61. // RGB color values
  62. //
  63.  
  64. #define rgbWhite    RGB(255,255,255)
  65. #define rgbBlack    RGB(0,0,0)
  66.  
  67. //
  68. // Flags used for the Redraw function
  69. //
  70.  
  71. #define UPDATE_SCREEN   TRUE
  72. #define NO_UPDATE       FALSE
  73.  
  74. //
  75. // update system
  76. //
  77.  
  78. #define WAIT_LOOP               // comment out to use timer ticks
  79. #ifndef WAIT_LOOP
  80. #define TIMER_TICKS
  81. #endif
  82.  
  83. //
  84. // Various types
  85. //
  86.  
  87. typedef char huge *HPSTR;
  88. typedef BYTE huge *HPBYTE;
  89.  
  90. typedef LPBITMAPINFO PDIB;
  91.  
  92. typedef struct _SPRITE {
  93.     struct _SPRITE FAR *pNext;  // pointer to the next item
  94.     struct _SPRITE FAR *pPrev;  // pointer to the prev item
  95.     PDIB pDIB;                  // The DIB image of the sprite
  96.     int x;                      // X Coordinate of top-left corner
  97.     int y;                      // Y Coordinate of top-left corner
  98.     int z;                      // Z order for sprite
  99.     int vx;                     // X velocity
  100.     int vy;                     // Y velocity
  101.     int width;                  // width of bounding rectangle
  102.     int height;                 // height of bounding rectangle
  103.     BYTE bTopLeft;              // top left pixel value
  104.     COLORREF rgbTopLeft;        // top left pixel color
  105.     BOOL bSelectable;           // TRUE if sprite can be mouse selected
  106. } SPRITE, FAR *PSPRITE;
  107.  
  108. //
  109. // define a structure used to maintain rectangle lists
  110. // Note: these are allocated on the local heap and we use
  111. // near pointers deliberately for speed.
  112. //
  113.  
  114. typedef struct _DRAWRECT {
  115.     struct _DRAWRECT *pPrev;    // pointer to the prev one
  116.     struct _DRAWRECT *pNext;    // pointer to the next one
  117.     RECT rc;                    // the data item
  118. } DRAWRECT, *PDRAWRECT;
  119.  
  120. typedef struct _DRAWRECTLIST {
  121.     PDRAWRECT pHead;                // pointer to the first item
  122. } DRAWRECTLIST, FAR *PDRAWRECTLIST;
  123.  
  124.  
  125. //
  126. // macros to access the fields in a BITMAPINFO struct
  127. // field_value = macro(pBitmapInfo)
  128. //
  129.  
  130. #define BI_WIDTH(pBI)       (int)((pBI)->bmiHeader.biWidth)
  131. #define BI_HEIGHT(pBI)      (int)((pBI)->bmiHeader.biHeight)
  132. #define BI_PLANES(pBI)      ((pBI)->bmiHeader.biPlanes)
  133. #define BI_BITCOUNT(pBI)    ((pBI)->bmiHeader.biBitCount)
  134. #define BI_CLRUSED(pBI)     ((pBI)->bmiHeader.biClrUsed)
  135.  
  136. //
  137. // macros to access BITMAPINFO fields in a DIB
  138. // field_value = macro(pDIB)
  139. //
  140.  
  141. #define DIB_WIDTH(pDIB)     (BI_WIDTH((LPBITMAPINFO)(pDIB)))
  142. #define DIB_HEIGHT(pDIB)    (BI_HEIGHT((LPBITMAPINFO)(pDIB)))
  143. #define DIB_PLANES(pDIB)    (BI_PLANES((LPBITMAPINFO)(pDIB)))
  144. #define DIB_BITCOUNT(pDIB)  (BI_BITCOUNT((LPBITMAPINFO)(pDIB)))
  145. #define DIB_CLRUSED(pDIB)   (BI_CLRUSED((LPBITMAPINFO)(pDIB)))
  146. #define DIB_COLORS(pDIB)    (NumDIBColorEntries((LPBITMAPINFO)(pDIB)))
  147. #define DIB_PCLRTAB(pDIB)   ((LPRGBQUAD)(((LPSTR)((LPBITMAPINFO)(pDIB))) \
  148.                             + sizeof(BITMAPINFOHEADER)))
  149. #define DIB_BISIZE(pDIB)    (sizeof(BITMAPINFOHEADER) \
  150.                             + DIB_COLORS(pDIB) * sizeof(RGBQUAD))
  151. #define DIB_PBITS(pDIB)     (((LPSTR)((LPBITMAPINFO)(pDIB))) \
  152.                             + DIB_BISIZE(pDIB))
  153. #define DIB_PBI(pDIB)       ((LPBITMAPINFO)(pDIB))
  154. #define DIB_STORAGEWIDTH(pDIB) ((DIB_WIDTH(pDIB) + 3) & ~3)
  155.  
  156.  
  157. //
  158. // global data
  159. //
  160.  
  161. char *szAppName;                // App name
  162. HINSTANCE hAppInstance;         // app instance
  163. HWND hwndMain;                  // main window handle
  164. TEXTMETRIC tmSysFont;           // system font metrics
  165. HANDLE hAccTable;               // accelerator table
  166. UINT uiCfSprite;                // private clipboard format
  167. PSPRITE pSpriteList;            // pointer to the list of sprites
  168. PDIB pdibBkGnd;                 // background DIB
  169. PDIB pdibOffScreen;             // off-screen DIB for off-screen DC
  170. HDC hdcOffScreen;               // main off-screen DC
  171. LPBITMAPINFO pPalClrTable;      // A 1:1 color lookup table for the os DC
  172. UINT uiTimer;                   // update timer
  173. HPALETTE hpalCurrent;           // the current application palette
  174. BOOL bShowUpdateRects;          // show update rectangles
  175. char szIniFile[_MAX_PATH];      // INI file name
  176. BOOL bAutoUpdate;
  177.  
  178. //
  179. // memory allocation macros
  180. //
  181.  
  182. HANDLE __hMem;
  183.  
  184. #define ALLOCATE(s) ((__hMem = GlobalAlloc(GHND, (DWORD)(s))) ? GlobalLock(__hMem) : NULL)
  185. #define FREE(p) (GlobalUnlock((HANDLE)HIWORD(p)),GlobalFree((HANDLE)HIWORD(p)))
  186. #define SIZE(p) (GlobalSize((HANDLE)HIWORD(p)))
  187.  
  188. //
  189. // main.c
  190. //
  191.  
  192. extern LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  193. extern UINT cdecl Message(UINT uiBtns, LPSTR lpFormat, ...) ;
  194.  
  195. //
  196. // init.c
  197. //
  198.  
  199. extern BOOL InitFirstInstance(HANDLE hInstance);
  200. extern BOOL InitCurrentInstance(HANDLE hInstance, LPSTR lpszCmdLine, int cmdShow);
  201. extern void Terminate(void);
  202. extern void LoadScene(LPSTR pFileName);
  203.  
  204. //
  205. // help.c
  206. //
  207.  
  208. extern void About(HWND hWnd);
  209. extern void Help(HWND hWnd, WORD wParam);
  210.  
  211. //
  212. // file.c
  213. //
  214.  
  215. // <dwFlags> for PromptForFileName()
  216. #define PFFN_OPENFILE        0x0001    // prompt to open a file
  217. #define PFFN_SAVEFILE        0x0002    // prompt to save a file
  218. #define PFFN_SHOWDEFAULT     0x0004    // init. show what's in <achFileName>
  219. #define PFFN_OVERWRITEPROMPT 0x0008    // prompt the user about overwriting
  220. #define PFFN_UPPERCASE       0x0010    // make the name uppercase
  221.  
  222. extern char *szOpenFilter;
  223. extern char *szIniFilter;
  224.  
  225. extern BOOL PromptForFileName(HWND hwndOwner,
  226.                               HANDLE hInst,
  227.                               LPSTR achFileName,
  228.                               WORD cchFileName,
  229.                               LPSTR szCaption,
  230.                               LPSTR szFilter,
  231.                               LPSTR szDefExt,
  232.                               DWORD dwFlags);
  233.  
  234. //
  235. // print.c
  236. //
  237.  
  238. extern void Print(HDC hDC);
  239.  
  240. //
  241. // Debug support
  242. //
  243.  
  244. extern LRESULT CALLBACK DebugWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  245.  
  246. #ifdef DEBUG
  247.  
  248.     DWORD   __dwEval;
  249.     int __iDebugLevel;
  250.  
  251.     extern void SetDebugLevel(int i);
  252.     extern void __AssertMsg(LPSTR exp ,LPSTR file, int line);
  253.     extern void cdecl DbgOut(LPSTR lpFormat, ...);
  254.  
  255.     #define ASSERT(exp) \
  256.         ((exp) ? (void)0 : __AssertMsg((LPSTR)(#exp), (LPSTR)__FILE__, __LINE__))
  257.     #define EVAL(exp) \
  258.         (__dwEval=(DWORD)(exp), (__dwEval) ? (void)0 : __AssertMsg((LPSTR)(#exp), (LPSTR)__FILE__, __LINE__), __dwEval)
  259.  
  260.     #define dprintf                          DbgOut
  261.     #define dprintf1 if (__iDebugLevel >= 1) DbgOut
  262.     #define dprintf2 if (__iDebugLevel >= 2) DbgOut
  263.     #define dprintf3 if (__iDebugLevel >= 3) DbgOut
  264.     #define dprintf4 if (__iDebugLevel >= 4) DbgOut
  265.  
  266. #else // not DEBUG
  267.  
  268.     #define ASSERT(exp) 0
  269.     #define EVAL(exp) (exp)
  270.  
  271.     #define dprintf  if (0) ((int (*)(char *, ...)) 0)
  272.     #define dprintf1 if (0) ((int (*)(char *, ...)) 0)
  273.     #define dprintf2 if (0) ((int (*)(char *, ...)) 0)
  274.     #define dprintf3 if (0) ((int (*)(char *, ...)) 0)
  275.     #define dprintf4 if (0) ((int (*)(char *, ...)) 0)
  276.  
  277. #endif // DEBUG
  278.  
  279. //
  280. // ppdbg.asm
  281. // Debug macros which set, pulse or clear printer port bits
  282. // see ppdbg.asm for details
  283. //
  284.  
  285. #ifdef PPDBG
  286.  
  287.     extern void FAR PASCAL ppdbgSet(BYTE mask);
  288.     extern void FAR PASCAL ppdbgClear(BYTE mask);
  289.     extern void FAR PASCAL ppdbgPulse(BYTE mask);
  290.  
  291.     #define DBGSET(x)   ppdbgSet(x)
  292.     #define DBGCLEAR(x) ppdbgClear(x)
  293.     #define DBGPULSE(x) ppdbgPulse(x)
  294.  
  295. #else // PPDBG
  296.  
  297.     #define DBGSET(x)   0
  298.     #define DBGCLEAR(x) 0
  299.     #define DBGPULSE(x) 0
  300.  
  301. #endif // PPDBG
  302.  
  303. //
  304. // bkgnd.c
  305. //
  306.  
  307. extern void LoadBackground(LPSTR pszPath, BOOL bUpdateScreen);
  308.  
  309. //
  310. // palette.c
  311. //
  312.  
  313. extern HPALETTE CreateDIBPalette(LPBITMAPINFO lpBmpInfo);
  314. extern LRESULT PaletteMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  315. extern HPALETTE CopyPalette(HPALETTE hSrcPal);
  316. extern void SetSysPalColors(HPALETTE hPal);
  317.  
  318. //
  319. // draw.c
  320. //
  321.  
  322. extern void RenderDIBOffScreen(PDIB pDIB, int iX, int iY, LPRECT prcClip);
  323. extern void Paint(HDC hDC, LPRECT prcClip);
  324. extern void UpdatePositions(void);
  325. extern void FillBkGnd(void);
  326. extern void Redraw(LPRECT prcClip, BOOL bUpdateScreen);
  327. extern PDRAWRECTLIST CreateDrawRectList(void);
  328. extern void DeleteDrawRectListItem(PDRAWRECTLIST pList, PDRAWRECT pItem);
  329. extern void EmptyDrawRectList(PDRAWRECTLIST pList);
  330. extern void AddDrawRectItem(PDRAWRECTLIST pList, LPRECT pRect);
  331. extern void MergeDrawRectList(PDRAWRECTLIST pList);
  332.  
  333.  
  334.  
  335.  
  336. //
  337. // sprite.c
  338. //
  339.  
  340. extern PSPRITE SpriteHitTest(int x, int y);
  341. extern void SetSpritePosition(PSPRITE pSprite, int x, int y, BOOL bUpdate);
  342. extern void GetSpriteRect(PSPRITE pSprite, LPRECT prcSprite);
  343. extern PSPRITE LoadSprite(LPSTR pszPath, BOOL bRedraw);
  344. extern void DeleteSprite(PSPRITE pSprite);
  345. extern void DeleteSpriteList(void);
  346. extern void SetSpriteZOrder(PSPRITE pSprite, WORD z, BOOL bUpdate);
  347. extern void SpriteDialog(PSPRITE pSprite);
  348. extern BOOL IsSpriteSelectable(PSPRITE pSprite);
  349.  
  350. //
  351. // dib.c
  352. //
  353.  
  354. extern PDIB LoadDIB(LPSTR pszPath);
  355. extern void DeleteDIB(PDIB pDIB);
  356. extern BYTE GetDIBPixelValue(PDIB pDIB, int x, int y);
  357. extern COLORREF GetDIBPixelColor(PDIB pDIB, int x, int y);
  358. extern BOOL IsWinDIB(LPBITMAPINFOHEADER pBI);
  359. extern void ShowInfo(LPBITMAPINFO lpBmpInfo);
  360. extern WORD NumDIBColorEntries(LPBITMAPINFO lpBmpInfo);
  361. extern PDIB CreateCompatibleDIB(PDIB pOld);
  362. extern HPSTR GetDIBPixelAddress(PDIB pDIB, int x, int y);
  363. extern void MapDIBColorTable(PDIB pdibObj, PDIB pdibRef);
  364.  
  365. //
  366. // fast.asm
  367. //
  368.  
  369. extern FAR PASCAL TransCopyDIBBits(HPBYTE pD, 
  370.                                    HPBYTE pS, 
  371.                                    DWORD dwWidth, 
  372.                                    DWORD dwHeight,
  373.                                    DWORD dwScanD,
  374.                                    DWORD dwScanS,
  375.                                    BYTE bTranClr);
  376.  
  377. extern FAR PASCAL CopyDIBBits(HPBYTE pD, 
  378.                               HPBYTE pS, 
  379.                               DWORD dwWidth, 
  380.                               DWORD dwHeight,
  381.                               DWORD dwScanD,
  382.                               DWORD dwScanS);
  383.